<template>
	<view>
		<image src="../../static/login/top.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.png" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">（司机端）</text>
			<text class="version">Version 2022.11</text>
		</view>
		<button class="btn" @tap="login()">微信登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">本小程序仅限于随行打车签约司机使用，新司机必须先注册，经由实名认证之后方可在本小程序中接单运营。</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {};
	},
	methods: {
		toRegisterPage(){
			uni.navigateTo({
				url:"../register/register"
			})
		},
		login(){
			let self = this;
			uni.login({
				provider:'weixin',
				success(res) {
					let code = res.code;
					let data ={
						code: code
					};
					self.ajax(self.url.login, "POST", data, function(resp){
						if(!resp.data.hasOwnProperty('token')) {
							self.$refs.uToast.show({
								title: "请先完成注册",
								type: "error"
							});
						} else {
							let token = resp.data.token;
							let realAuth = resp.data.realAuth;
							let archive = resp.data.archive;
							uni.setStorageSync('token', token);
							uni.setStorageSync('realAuth', realAuth);
							//删除缓存的执行订单数据，进入工作台重新加载数据
							uni.removeStorageSync("executeOrder");
							self.$refs.uToast.show({
								title: '登录成功',
								duration: 600,
								type: 'success',
								callback(){
									uni.setStorageSync('workStatus', '停止接单');
									//没有实名认证,跳转至认证页面
									if(realAuth == 1) {
										uni.showToast({
											title: '未实名认证，请先完成实名认证！',
											icon: 'none'
										})
										uni.redirectTo({
											url: '../../identity/filling/filling?mode=create'
										});
									}
									//检查司机是否录入人脸数据
									else if(archive == false) {
										uni.showModal({
											title: '提示消息',
											content: '您还没有录入用于核实身份的面部特征信息，如果不录入将无法接单',
											confirmText: '录入',
											cancelText: '取消',
											success(res) {
												if(res.confirm) {
													//跳转到面部识别页面，采集人脸数据
													uni.redirectTo({
														url: '../../identity/face_camera/face_camera?mode=create'
													});
												} else {
													uni.switchTab({
														url: '../workbench/workbench'
													})
												}
											}
										})
									}
									//进入工作台
									else {
										uni.switchTab({
											url: '../workbench/workbench'
										})
									}
								}
							})
						}
					});
				}
			})
		}
	},
	onLoad: function() {
		
	}
};
</script>

<style lang="less">
@import url('login.less');
</style>
